#include "SpriteInfoPanel.hpp"

SpriteInfoPanel::SpriteInfoPanel():Panel(0,505, 200, 95, Panel::Static){
    selectedSprite = 0;
    spriteButton = 0;
    
    spriteName = new Label(42, 20, 10, sf::Color::White, "");
    spriteSheetName = new Label(42, 37, 10, sf::Color::White, "");
    spriteType = new Label(72, 54, 10, sf::Color::White, "");
    spriteWidth = new Label(5, 54, 10, sf::Color::White, "");
    spriteHeight = new Label(5, 71, 10, sf::Color::White, "");
    
    title = new Label(5, 2, 10, sf::Color::White, sf::Text::Underlined, "Selected Brush");
    add(title);

    add(spriteName);
    add(spriteSheetName);
    add(spriteType);
    add(spriteWidth);
    add(spriteHeight);

    setSelectedSprite(0);
}

/** 
* Sets the selected sprite.
* Updates all the information and icon of the selected information.
* @param selected The selected sprite.
*/
void SpriteInfoPanel::setSelectedSprite(BaseSprite* selected){

    selectedSprite = selected;
    //Change the iconbutton icon.
    if(spriteButton == 0){
        spriteButton = new IconButton(5, 20, 32, 32, selectedSprite);
        add(spriteButton);
    }else{
        spriteButton->setIcon(selectedSprite);
    }

    if(selected != 0){
        //Set sprite info
        if(selected->name)
            spriteName->setString(selected->name);
        //spriteSheetName->setString(selectedSprite->sheetName);
        if(selectedSprite->type == BaseSprite::st_Static){
            spriteType->setString("Type: Static");
            spriteWidth->setString(string("Width: ").append(StringHelper::itos(((StaticSprite*)selectedSprite)->getSprite().getTextureRect().width)));
            spriteHeight->setString(string("Height: ").append(StringHelper::itos(((StaticSprite*)selectedSprite)->getSprite().getTextureRect().height)));
        }else if(selectedSprite->type == BaseSprite::st_Animated){
            spriteType->setString("Type: Animated");
        }else if (selectedSprite->type == BaseSprite::st_Layered){
            spriteType->setString("Type: Layered");
        }
    }
}